import request from '@/utils/request'

const PREFIX = '/system/dict'

/**
 * 查询字典列表
 */
export function listDict(params) {
  return request.get(`${PREFIX}/list`, {
    params,
  })
}

/**
 * 查询字典列表
 */
export async function pageDict(params) {
  const res = await request.get(`${PREFIX}/index`, {
    params,
  })
  if (res.code === 0)
    return res.data

  return Promise.reject(new Error(res.msg))
}

/**
 * 新增、修改字典
 */
export async function updateDict(data) {
  return request.post(`${PREFIX}/edit`, data)
}

/**
 * 删除字典
 */
export async function removeDict(id) {
  const res = await request.post(`${PREFIX}/delete`, { id })
  if (res.code === 0)
    return res.msg

  return Promise.reject(new Error(res.msg))
}
